<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Boost搜索引擎</title>
    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        html,
        body {
            height: 100%;
            transition: background 0.5s;
        }

        #canvas {
            position: fixed;
            top: 0;
            left: 0;
            pointer-events: none;
            z-index: 1;
        }

        /* 侧边栏样式 */
        .sidebar-toggle {
            position: fixed;
            top: 20px;
            right: 20px;
            z-index: 100;
            background: #4e6ef2;
            color: white;
            border: none;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            cursor: pointer;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
            transition: transform 0.3s;
        }

        .sidebar-toggle:hover {
            transform: scale(1.1);
        }

        .bg-controls.sidebar {
            position: fixed;
            top: 0;
            right: -250px;
            width: 250px;
            height: 100%;
            background: rgba(255, 255, 255, 0.95);
            box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
            transition: right 0.3s;
            display: flex;
            flex-direction: column;
            gap: 15px;
            z-index: 99;
        }

        .bg-controls.sidebar.active {
            right: 0;
        }

        /* 容器和标题 */
        .container {
            width: 90%;
            max-width: 800px;
            margin: 120px auto 20px;
            position: relative;
            z-index: 2;
        }

        .search-title {
            font-size: 3em;
            color: #4e6ef2;
            text-align: center;
            margin-bottom: 30px;
            font-family: 'Arial Black', sans-serif;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
        }

        /* 搜索框样式 */
        .search {
            width: 100%;
            height: 50px;
            margin-bottom: 20px;
        }

        .search input {
            float: left;
            width: 650px;
            height: 50px;
            padding: 0 25px;
            border: 2px solid #ddd;
            border-right: none;
            border-radius: 25px 0 0 25px;
            font-size: 16px;
            outline: none;
            transition: border-color 0.3s;
        }

        .search input:focus {
            border-color: #4e6ef2;
        }

        .search button {
            float: left;
            width: 150px;
            height: 52px;
            background: #4e6ef2;
            border: none;
            border-radius: 0 25px 25px 0;
            color: white;
            font-size: 18px;
            cursor: pointer;
            transition: background 0.3s;
        }

        .search button:hover {
            background: #4662d5;
        }

        /* 搜索结果 */
        .result {
            width: 100%;
        }

        .item {
            background: rgba(255, 255, 255, 0.95);
            padding: 20px;
            margin: 15px 0;
            border-radius: 12px;
            box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
            border: 1px solid #eee;
            overflow-wrap: break-word;
            word-wrap: break-word;
        }

        .item a {
            display: block;
            text-decoration: none;
            font-size: 20px;
            color: #4e6ef2;
            margin-bottom: 8px;
            font-weight: 500;
        }

        .item a:hover {
            text-decoration: underline;
        }

        .item p {
            font-size: 16px;
            color: #444;
            line-height: 1.6;
            margin: 10px 0;
            overflow-wrap: break-word;
        }

        .item .url {
            display: block;
            font-style: normal;
            color: #00a000;
            font-size: 14px;
            word-break: break-all;
            padding-top: 8px;
            border-top: 1px solid #eee;
            margin-top: 12px;
        }

        .highlight {
            color: #ff4444;
            font-weight: bold;
            background: rgba(255, 68, 68, 0.1);
            padding: 2px 4px;
            border-radius: 3px;
        }

        /* 移动端适配 */
        @media (max-width: 768px) {
            .container {
                width: 95%;
                margin-top: 100px;
            }

            .search-title {
                font-size: 2em;
                margin-bottom: 20px;
            }

            .search input {
                width: 65%;
            }

            .search button {
                width: 35%;
            }

            .bg-controls.sidebar {
                width: 80%;
                right: -80%;
            }
        }
    </style>
</head>

<body>
    <canvas id="canvas"></canvas>

    <!-- 侧边栏触发按钮 -->
    <button class="sidebar-toggle" onclick="toggleSidebar()">☰</button>

    <!-- 侧边栏 -->
    <div class="bg-controls sidebar">
        <input type="color" id="bgColor" onchange="changeBg(this.value)">
        <button onclick="randomBg()">随机背景</button>
    </div>
    <div class="container">
        <h1 class="search-title">Boost搜索引擎</h1>
        <div class="search">
            <form onsubmit="Search(); return false;">
                <input type="text" placeholder="输入搜索内容...">
                <button type="submit">搜索一下</button>
            </form>
        </div>
        <div class="result"></div>
    </div>
    <script>
        // 烟花效果
        const canvas = document.getElementById('canvas');
        const ctx = canvas.getContext('2d');
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;

        class Particle {
            constructor(x, y) {
                this.x = x;
                this.y = y;
                this.velocity = {
                    x: (Math.random() - 0.5) * 5,
                    y: (Math.random() - 0.5) * 5
                };
                this.alpha = 1;
                this.color = `hsl(${Math.random() * 360}, 100%, 50%)`;
            }

            draw() {
                ctx.fillStyle = this.color;
                ctx.globalAlpha = this.alpha;
                ctx.beginPath();
                ctx.arc(this.x, this.y, 2, 0, Math.PI * 2);
                ctx.fill();
            }

            update() {
                this.x += this.velocity.x;
                this.y += this.velocity.y;
                this.alpha -= 0.01;
            }
        }

        let particles = [];
        document.addEventListener('click', (e) => {
            for (let i = 0; i < 50; i++) {
                particles.push(new Particle(e.clientX, e.clientY));
            }
        });

        function animate() {
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            particles = particles.filter(p => p.alpha > 0);
            particles.forEach(p => {
                p.update();
                p.draw();
            });
            requestAnimationFrame(animate);
        }
        animate();

        // 搜索功能
        function Search() {
            const query = $(".search input").val().trim();
            if (query.length < 2) return;

            $.ajax({
                type: "GET",
                url: "/s?word=" + encodeURIComponent(query),
                success: function (data) {
                    BuildHtml(data, query);
                }
            });
        }

        function BuildHtml(data, query) {
            const resultDiv = $(".result");
            resultDiv.empty();

            for (let elem of data) {
                const highlightedTitle = highlightKeywords(elem.title, query);
                const highlightedDesc = highlightKeywords(elem.desc, query);

                const item = $(`
                    <div class="item">
                        <a href="${elem.url}" target="_blank">${highlightedTitle}</a>
                        <p>${highlightedDesc}</p>
                        <span class="url">${elem.url}</span>./
                    </div>
                `);
                resultDiv.append(item);
            }
        }

        function highlightKeywords(text, query) {
            const regex = new RegExp(`(${query})`, 'gi');
            return text.replace(regex, '<span class="highlight">$1</span>');
        }

        // 背景控制
        function changeBg(color) {
            document.body.style.background = color;
        }

        function randomBg() {
            const colors = ['#f8f9fa', '#fff3cd', '#e2f0d9', '#f5e6e8'];
            document.body.style.background = colors[Math.floor(Math.random() * colors.length)];
        }

        // 侧边栏切换
        function toggleSidebar() {
            document.querySelector('.sidebar').classList.toggle('active');
        }
    </script>
</body>

</html>